App.module.UserRole.User.Delete = Ext.extend(Ext.util.Observable, {
	init: function(grid){
		this.grid = grid;
		grid.on('render', function(grid){
			var bt = new Ext.Button({
				tooltip: 'Delete'
				,iconCls: 'icon-delete-16x16'
				,disabled: true
				,handler: this.del
				,scope: this
			}, this);
			
			grid.getTopToolbar().add(bt);
			grid.selModel.on('selectionchange', function(sm){
				bt.setDisabled(!sm.hasSelection());	
			});
		}, this);	
	}
	,del: function(){
		var sm = this.grid.selModel;
		if(!sm.hasSelection()) return;
		
		Ext.Msg.confirm('Delete', 'Do you want to delete?', function(bt){
			if('no' == bt) return;
			
			var view = this.grid.getView();
			var store = this.grid.getStore();
			var records = sm.getSelections();
			var ids = [];
			var rows = [];
			
			for(var i = 0, len = records.length; i < len; i ++){
				ids.push(records[i].data.id);
			}
			store.remove(records);
			API.user.del({ids: ids});
		}, this);
	}
});